|
New to programming and need some help getting started ? - Well, then our tutorial section will help kick start your programming adventure.
If you're looking for more Source Code / Tutorials & Media ? - Then remember to visit the PlayBasic Resource board on our forums.
Found #1 item in Repeat category by Kevin Picone
Repeat / Until and While / EndWhile Control Loops In PlayBasic
|
By: Kevin Picone Added: January 7th, 2023
|
Category: All,Loops,Repeat,While,Learn to Code
|
REPEAT UNTIL LOOPS in PlayBasic
In PlayBasic, the Repeat/Until control structure allows you to repeatedly execute a block of code until a certain condition is met. The syntax for the Repeat/Until structure is as follows:
Repeat
' code to be executed repeatedly
Until condition
The code block between Repeat and Until will be executed repeatedly until the condition is met. When the condition is met, the loop will exit and control will be passed to the next line of code after the Until statement.
Here is an example of a Repeat/Until loop in PlayBasic:
x = 0
Repeat
x = x + 1
Print x
Until x = 10
Print "Loop complete"
sync
waitkey
In this example, the loop will repeat 10 times, printing the value of x each time. When x reaches 10, the Until condition will be met and the loop will exit. The message "Loop complete" will then be printed.
Read PlayBasic Help Files about LOOPS
While / EndWhile Control Structures In PlayBasic
In PlayBasic, the While/EndWhile control structure allows you to repeatedly execute a block of code as long as a certain condition is met. The syntax for the While/EndWhile structure is as follows:
While condition
' code to be executed repeatedly
EndWhile
The code block between While and EndWhile will be executed repeatedly as long as the condition is met. When the condition is no longer met, the loop will exit and control will be passed to the next line of code after the EndWhile statement.
Here is an example of a While/EndWhile loop in PlayBasic:
x = 0
While x < 10
x = x + 1
Print x
EndWhile
Print "Loop complete"
sync
waitkey
In this example, the loop will repeat until x is no longer less than 10. The loop will print the value of x each time it is executed, and when x reaches 10 the While condition will no longer be met and the loop will exit. The message "Loop complete" will then be printed.
Read PlayBasic Help Files about LOOPS
|
|
|
Viewing Page [1] of [0]
Looking for More Tutorials?:
|
|