Showing posts with label loop. Show all posts
Showing posts with label loop. Show all posts

Do Loops on Visual Basic

A Do Loop executes a line, or lines of code until a specific condition is met. It is sometimes referred as Do While Loops to some.

For example, you want to let the user enter names in a database until the user types the word Finish in an input box, or maybe until the user clicks the Done button. In that case, you can use a Do [While] Loop cycle until the next string Finish is entered or until the user clicks the Done button.

A Do [While] Loop has several formats, depending on where and how the loop condition is evaluated. The most common syntax used is:

Do While (condition)
       code block
       or
       block of statements
       to be executed
Loop




More examples will be posted soon.




Based on the book, Step by Step Microsoft Visual Basic 6.0

All in One

I'm in the middle of creating a program [Java] with the help of two other pals I got in school. We will actually defend that program within this week. We are required to use four out of the five statements, namely:

  • If statement (which includes the Dangling If's and others)
  • Arrays (Whether the normal array or the 2D)
  • Switch (commonly known as Case)
  • Loop (any of the loops)
So array is divided into two which means we have the power to choose which array to use, and that makes it four.

I'll post the code as soon as we are able to merge our codes. Further discussions would be available regarding the program.

Problem: Loop

create a program based on the sample output below:

Enter Number: 5
*
**
***
****
*****


import java.io.*;
class s31
{
public static void main (String args[]) throws IOException
{
DataInputStream ethel=new DataInputStream (System.in);

int ctr;

System.out.println("Enter number ");
ctr=Integer.parseInt(ethel.readLine());


for(int i = 1; i <=ctr; i++)

{ for(int j = 1; j <=i; j++)
{ System.out.print("*"); }
System.out.println(); } } }

Loops

There are three different kinds of loops: while, for, and do-while loops.

The uses of these loops are almost alike. But, there are some cases that they're different. It only depends on how you use it.

FOR LOOP

  • repeats for a specified number of times
Syntax:
for(initialization; comparison ;increment or decrement)
{statements;}

WHILE LOOP
  • a loop that repeats until a certain condition is satisfied
Syntax:
while(condition)
{statements;)


DO-WHILE LOOP
  • unlike the while loop, the do-while loop tests the condition at the end of the loop
Syntax:
do
{statements;}
while(condition);

Extended Search

Custom Search
Hello World