W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
VB.Net允許在另一個(gè)循環(huán)內(nèi)使用一個(gè)循環(huán)。 以下部分顯示了幾個(gè)例子來(lái)說(shuō)明這個(gè)概念。
For counter1 [ As datatype1 ] = start1 To end1 [ Step step1 ] For counter2 [ As datatype2 ] = start2 To end2 [ Step step2 ] ... Next [ counter2 ] Next [ counter 1]
VB.Net中嵌套While循環(huán)語(yǔ)句的語(yǔ)法如下:
While condition1 While condition2 ... End While End While
VB.Net中嵌套Do ... While循環(huán)語(yǔ)句的語(yǔ)法如下:
Do { While | Until } condition1 Do { While | Until } condition2 ... Loop Loop
關(guān)于循環(huán)嵌套的最后一點(diǎn)是,你可以把任何類(lèi)型的循環(huán)放在任何其他類(lèi)型的循環(huán)里面。 例如,for循環(huán)可以在while循環(huán)內(nèi),反之亦然。
Module loops Sub Main() ' local variable definition Dim i, j As Integer For i = 2 To 100 For j = 2 To i ' if factor found, not prime If ((i Mod j) = 0) Then Exit For End If Next j If (j > (i \ j)) Then Console.WriteLine("{0} is prime", i) End If Next i Console.ReadLine() End Sub End Module
2 is prime 3 is prime 5 is prime 7 is prime 11 is prime 13 is prime 17 is prime 19 is prime 23 is prime 29 is prime 31 is prime 37 is prime 41 is prime 43 is prime 47 is prime 53 is prime 59 is prime 61 is prime 67 is prime 71 is prime 73 is prime 79 is prime 83 is prime 89 is prime 97 is prime
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: