VBScript Loop Statements
- Previous Page VB Conditional Statements
- Next Page VB Tutorial Summary
مثال
- دورة For..next
- هذا المثال يوضح كيفية كتابة دورة For....Next بسيطة.
- إخراج عناوين HTML دوريًا
- هذا المثال يوضح كيفية إنشاء 6 عناوين HTML باستمرار.
- دورة For..each
- هذا المثال يوضح كيفية كتابة دورة For.....Each بسيطة.
- دورة Do...While
- هذا المثال يوضح كيفية كتابة دورة Do...While بسيطة.
جملة الدوران
غالبًا، عند كتابة الكود، نريد تنفيذ جملة معينة عدة مرات. يمكننا استخدام جملة الدوران في الكود لتحقيق ذلك.
في VBScript، يمكننا استخدام أربعة جمل دائرية:
- جملة For...Next
- تشغيل جملة من قبلها مرة معينة
- جملة For Each...Next
- للاجتماع على كل مشروع أو عنصر في المجموعة أو كل عنصر في قائمة.
- Do...Loop Statement
- Run the loop when the condition is true or until the condition is true.
- While...Wend Statement
- Do not use this statement - please use the Do...Loop statement instead.
For...Next Loop
If you have already determined the number of times you need to repeat the code, you can use the For...Next statement to run this code.
We can use a counter variable that will increase or decrease with each loop, for example:
For i=1 to 10 some code Next
The For statement specifies the counter variable and its starting and ending values.
The Next statement will increment the variable i by 1 as the step value.
Step Keyword
By using the Step keyword, we can specify the increment or decrement step value of the counter variable.
In the following example, the increment step value of the counter variable i is 2 each time the loop is executed.
For i=2 To 10 Step 2 some code Next
If you want to decrement the counter variable, you must use a negative step value. And you need to specify an end value less than the starting value.
In the following example, the decrement step value of the counter variable i is 2 each time the loop is executed.
For i=10 To 2 Step -2 some code Next
Exit For...Next
To exit the For...Next statement, you can use the Exit keyword.
- Previous Page VB Conditional Statements
- Next Page VB Tutorial Summary