Monday, August 2, 2010

Example of C++ Do While

Codes:

#include
#include
void main()
{
Clrscr();
int i = 0;
do
{
printf("%d",i++);
} while (i < 3);
}

Output:
1 2 3

C++ Do while Statement

The do-while loop is similar to the while loop, except that the test condition occurs at the end of the loop. Having the test condition at the end, guarantees that the body of the loop always executes at least one time. The format of the do-while loop is shown in the box at the right.
The test condition must be enclosed in parentheses and FOLLOWED BY A SEMI-COLON. Semi-colons also follow each of the statements within the block. The body of the loop (the block of code) is enclosed in braces and indented for readability. (The braces are not required if only ONE statement is used in the body of the loop.)
The do-while loop is an exit-condition loop. This means that the body of the loop is always executed first. Then, the test condition is evaluated. If the test condition is TRUE, the program executes the body of the loop again. If the test condition is FALSE, the loop terminates and program execution continues with the statement following the while.

Syntax:

do
{
Statment;
}while(condition);

Example of C++ For Loop

Counting from 1 to 5

Codes:
#include
#include

void main ()
{
clrscr();

int x,y=0; <-- I assign the value 0 to y to initialize.

For(x=1;x<=5;x++) <-- This funtion is the for loop. It varies or counts the loop 1-5.
{
y = y++;
Printf("y");
}
getch();
}

Output:
1 2 3 4 5

C++ For Loop Statement

This C++ for loop tutorial is written for beginning C++ students without previous C++ programming experience. There are C++ questions about the for loop inside the tutorial, for the students to answer and many code examples and explanations about the conditions of a C++ for loop. Some of the for loop examples have an if/else structure within the for loop structure.
 
The format of a for loop is:

for(Initialization;Condition;Status)
{
Statement/Statments;
}

Hello World C++

This program is most basic part of the C++. It enables you to Print out a certain word of "Hello World".

Codes:
#include <--- Directory of the TCPLUS
#include <--- Directory of the TCPLIB

Void Main ()
{ <-- Start of the Program
Clrscr(); <-- This function clears everything printed out.

Printf("Hello World"); <-- Printf functions that what will you print on the screen.
Remmember that ; functions stops the program.
getch();
} <-- End of the Program

After writing this program. Checking the program if theres and error is pressing Ctrl + F9.

#include
#include
Void Main ()
{
Clrscr();

Printf("Hello World");
getch();
}

Output:
Hello World

What is a computer program?

A computer program is a set of instructions that a programmer writes to tell a
computer how to carry out a certain task. The instructions, however, must be in a
language that the computer understands. Computers only understand binary language
i.e. that composed of 1’s and 0’s. This is a low level language and very hard to
program in. So humans invented higher level languages such as C++ or Pascal to
make the job easier. As you will see, these languages are nearly like English but you
don’t have the freedom to write what you like – there are still rules you have to
follow.
To convert a program in C++ to a binary or executable file that the computer can
understand we use a compiler. The compiler which I recommend using for this guide
is Borland’s command line compiler.

Introduction to C++

Welcome to my beginners guide to C++. If you are starting to program for the
first time, I hope that you find the chapters I have written useful. C++ is an excellent
language to start programming in – a lot of applications that you use are probably
written in c++ and once you learn some basic concepts, learning other languages, like
java for example, will be much easier.
There are 8 chapters altogether, including this one. I have kept the chapters short and
concise so you won’t get bored or weighed down by too much information. After each
chapter you can rearrange the code in the examples provided or make up your own
code. Programming is very much a practical subject so you will learn a lot by messing
about with code or even looking at other people’s code.