Question

In: Computer Science

explain what a while loop is and how you can use it. Give examples based on...

explain what a while loop is and how you can use it. Give examples based on websites on how you can use a while loop to your advantage. This assignment should be a couple paragraphs long (5-8 sentences per paragraph).

Solutions

Expert Solution

while is an iteration statement ,that represents a statement or block of statements untill some condition is true.

General form

while(condition)

{

// body of the loop

   }

Where condition may be any boolean expression.The body of loop will be executed as long as the condition is true.Once the condition becomes false, the control passes to the statement immediately after the while loop.

Example

1).    Class Test

  {

Public staic void main(string args[ ] )

{

int n=0;

while(n<10)

{

System.out.println("N:" +n);

n++;

}

}

}

.....................................................................................

2). Class ReverseLong

{

Public staic void main(string args[ ] )

{

Long 1=7562,reverse =0,temp,digits;

temp=1;

while(temp!=0)

{

digits=temp%10;

temp=temp/10;

reverse=reverse*10+digits;

}

  System.out.println("The original number is:" +1);

   System.out.println("Reverse of the original number is:" +reverse);

}

}

  

  

  

  

  

  


Related Solutions

This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your...
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console: #_#_#_#_# _#_#_#_#_ #_#_#_#_# _#_#_#_#_ #_#_#_#_#
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting...
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
explain how a firm can use capabilities and resources to create value. Give two examples of...
explain how a firm can use capabilities and resources to create value. Give two examples of each please write a detailed answer thanking you
Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
Give two examples of how you can support a person’s spiritual wellbeing. Give two examples of...
Give two examples of how you can support a person’s spiritual wellbeing. Give two examples of how you can support a person’s cultural well-being Give two examples of how you can support a person’s financial well-being. How is a person’s well-being enhanced through involvement in career or occupation? Give two examples of basic requirements that enhance a person’s mental health.
Give three examples of how you can use teach back method in your everyday work.
Give three examples of how you can use teach back method in your everyday work.
can you explain and compare chain polymerization can you give examples of each case
can you explain and compare chain polymerization can you give examples of each case
What is the difference between a for loop and a while loop? When is it ideal...
What is the difference between a for loop and a while loop? When is it ideal to use a for loop, and when is it ideal to use a while loop? Can they be used interchangeably? Does it depend on the circumstance? Furthermore, what is your professional opinion on the advisability of the absence of the do while loop in the MATLAB programming language? If you use outside resources or ideas that are not your own to help make your...
C programming. Explain by taking a programming example how do while loop is different from while...
C programming. Explain by taking a programming example how do while loop is different from while loop?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT