C Sharp Looping Statements

C Sharp Looping Statements

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

Is it possible to pass control to the next iteration without existing the loop? How?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

4 years ago

Date created

Mar 14, 2020

Cards (28)

Section 1

(28 cards)

Is it possible to pass control to the next iteration without existing the loop? How?

Front

Use the continue statement

Back

Quiz Question: What would be the output of the following while statement? class WhileTest3 { static void Main() { int n = 5; while (++n < 6) { Console.WriteLine("Current value of n is {0}", n); } } }

Front

None

Back

Example of a do loop?

Front

public class TestDoWhile { public static void Main () { int x = 0; do { Console.WriteLine(x); x++; } while (x < 5); } } /* Output: 0 1 2 3 4 */

Back

What is for loop?

Front

By using a for loop, you can run a statement or a block of statements repeatedly until a specified expression evaluates to false

Back

Example of Array

Front

int [] marks = new int[5] { 70, 78, 72, 77, 80};

Back

What is while loop?

Front

The while statement executes a statement or a block of statements until a specified expression evaluates to false.

Back

What is do loop?

Front

The do statement executes a statement or a block of statements enclosed in {} repeatedly until a specified expression evaluates to false.

Back

What is i++ in this example?

Front

Increment expression. It increments value of I by 1.

Back

What are the different sections of a for loop?

Front

Every for statement defines initializer, condition, and iterator sections. These sections usually determine how many times the loop iterates.

Back

The syntax and operation of while and do..while statements are the same in C Sharp and Java?

Front

Yes

Back

Is it possible to terminate a for loop?

Front

Yes by using break, goto, return or throw statements which transfers control outside the loop.

Back

Are the syntax and operation of for loops is the same in both C# and Java:?

Front

Yes

Back

Example of while loop?

Front

while (condition) { // statements }

Back

Examples of different sections of a for loop?

Front

for (initializer; condition; iterator) body

Back

Example of do-while loop?

Front

do { // statements } while(condition); // Don't forget the trailing ; in do...while loops

Back

What is foreach loop?

Front

The foreach loop enables iterating through each item in a container class, such as an array, that supports IEnuerable interface.

Back

What is array ?

Front

array is collection if similar type objects .arrays consist of contiguous memory locations. first element of array is always comes to 0 th index . syntax : datatype[] arrayName;

Back

What is i-- mean?

Front

Decrement expression. It decrements value of I by 1.

Back

Give an example of a foreach loop?

Front

class ForEachTest { static void Main(string[] args) { int[] fibarray = new int[] { 0, 1, 1, 2, 3, 5, 8, 13 }; foreach (int element in fibarray) { System.Console.WriteLine(element); } System.Console.WriteLine(); // Compare the previous loop to a similar for loop. for (int i = 0; i < fibarray.Length; i++) { System.Console.WriteLine(fibarray[i]); } System.Console.WriteLine(); // You can maintain a count of the elements in the collection. int count = 0; foreach (int element in fibarray) { count += 1; System.Console.WriteLine("Element #{0}: {1}", count, element); } System.Console.WriteLine("Number of elements in the array: {0}", count); } // Output: // 0 // 1 // 1 // 2 // 3 // 5 // 8 // 13 // 0 // 1 // 1 // 2 // 3 // 5 // 8 // 13 // Element #1: 0 // Element #2: 1 // Element #3: 1 // Element #4: 2 // Element #5: 3 // Element #6: 5 // Element #7: 8 // Element #8: 13 // Number of elements in the array: 8 }

Back

What is the difference between a while loop and do-while loop?

Front

Until the while statment a do-while loop is executed once before the conditional expression is evaluated.

Back

Give an example of a optional for statement?

Front

for (; ; ) { // ... }

Back

Example of a for loop is ?

Front

class Program { static void Main() { for (int i = 1; i <= 5; i++) { Console.WriteLine(i); } } } /* Output: 1 2 3 4 5 */

Back

Example of a while statement?

Front

class WhileTest { static void Main() { int n = 1; while (n < 6) { Console.WriteLine("Current value of n is {0}", n); n++; } } } /* Output: Current value of n is 1 Current value of n is 2 Current value of n is 3 Current value of n is 4 Current value of n is 5 */

Back

What are Looping Statements?

Front

Looping statements repeat a specified block of code until a given condition is met.

Back

Is it possible to pass control to the next iteration without existing the while-loop? How?

Front

Use the continue statement

Back

Are all of the expressions that define a for statement are optional?

Front

Yes

Back

Is it possible to terminate a while loop?

Front

Yes by using break, goto, return or throw statements which transfers control outside the loop.

Back

Example 2 of a while statement?

Front

class WhileTest2 { static void Main() { int n = 1; while (n++ < 6) { Console.WriteLine("Current value of n is {0}", n); } } } /* Output: Current value of n is 2 Current value of n is 3 Current value of n is 4 Current value of n is 5 Current value of n is 6 */

Back