File tree 5 files changed +106
-0
lines changed
W3School-CSExercises/CS-Loops
5 files changed +106
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * from C# Loops: Exercise 1 ( https://www.w3schools.com/cs/exercise.asp?filename=exercise_while_loop1 )
3
+ *
4
+ * question:
5
+ * Print i as long as i is less than 6.
6
+ *
7
+ * int i = 1;
8
+ * _____ (i _ 6)
9
+ * {
10
+ * Console.WriteLine(i);
11
+ * ___;
12
+ * }
13
+ *
14
+ */
15
+ int i = 1 ;
16
+ while ( i < 6 )
17
+ {
18
+ Console . WriteLine ( i ) ;
19
+ i ++ ;
20
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * from C# Loops: Exercise 2 ( https://www.w3schools.com/cs/exercise.asp?filename=exercise_while_loop2 )
3
+ *
4
+ * question:
5
+ * Use the do/while loop to print i as long as i is less than 6.
6
+ *
7
+ * int i = 1;
8
+ * __
9
+ * {
10
+ * Console.WriteLine(i);
11
+ * ___;
12
+ * }
13
+ * _____ (i _ 6);
14
+ *
15
+ */
16
+ int i = 1 ;
17
+ do
18
+ {
19
+ Console . WriteLine ( i ) ;
20
+ i ++ ;
21
+ }
22
+ while ( i < 6 ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * from C# Loops: Exercise 3 ( https://www.w3schools.com/cs/exercise.asp?filename=exercise_while_loop3 )
3
+ *
4
+ * question:
5
+ * Use a for loop to print "Yes" 5 times:
6
+ *
7
+ * ___ (int i = 0; i < 5; ___)
8
+ * {
9
+ * Console.WriteLine("Yes");
10
+ * }
11
+ *
12
+ */
13
+ for ( int i = 0 ; i < 5 ; i ++ )
14
+ {
15
+ Console . WriteLine ( "Yes" ) ;
16
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * from C# Loops: Exercise 4 ( https://www.w3schools.com/cs/exercise.asp?filename=exercise_while_loop4 )
3
+ *
4
+ * question:
5
+ * Stop the loop if i is 5.
6
+ *
7
+ * for (int i = 0; i < 10; i++)
8
+ * {
9
+ * if (i == 5)
10
+ * {
11
+ * _____;
12
+ * }
13
+ * Console.WriteLine(i);
14
+ * }
15
+ *
16
+ */
17
+ for ( int i = 0 ; i < 10 ; i ++ )
18
+ {
19
+ if ( i == 5 )
20
+ {
21
+ break ;
22
+ }
23
+ Console . WriteLine ( i ) ;
24
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * from C# Loops: Exercise 5 ( https://www.w3schools.com/cs/exercise.asp?filename=exercise_while_loop5 )
3
+ *
4
+ * question:
5
+ * In the following loop, when the value is "4", jump directly to the next value.
6
+ *
7
+ * for (int i = 0; i < 10; i++)
8
+ * {
9
+ * if (i == 4)
10
+ * {
11
+ * ________;
12
+ * }
13
+ * Console.WriteLine(i);
14
+ * }
15
+ *
16
+ */
17
+ for ( int i = 0 ; i < 10 ; i ++ )
18
+ {
19
+ if ( i == 4 )
20
+ {
21
+ continue ;
22
+ }
23
+ Console . WriteLine ( i ) ;
24
+ }
You can’t perform that action at this time.
0 commit comments