Easy Web Programming With PHP plus HTML 5 - part 1. Selection and Repetition / Iteration

In this module, you will learn some programming techniques and knowledge is important to note that often found in this program.

1 Adjusting the flow programming
A program can be accessed from the top to the bottom, top and bottom. If there is no flow control, this program will not be able to "Not much," and just execute the above code bottom only. For you to make the groove scheduling the use of multiple commands, Reports and switch.

1.1 " IF "  Statement
"If" is an important statement and certainly found in all programming languages. This statement is useful to create a branch based on certain conditions must be met.

If (certain conditions = True) {
action
}

Sample code for a program that uses the IF statement in PHP is:
    <? php
    $ Number = 20;
    print "The number". $ Number;
    print "</ br>";
    if ($ number% 2 == 0) {
    print "even number";
    }
    ?>
The above code will display the text "No. In fact," because Total = 20 is an even number. "==" Operator is used to compare the statement that the end result is the value True or false.


 1.1.1 If then to determine an even number or not
IF statement in the above code displays only one alternative solution, so that if the IF condition is not met, no action what and block any action code will be skipped. To create an alternative consists of 2 pieces, you can use the IF-ELSE in a way writing as follows:

if (certain conditions = True) {
Action if the condition is True
} Else {
Action if the condition is False
}

Examples of the use of IF-ELSE code looks like the following:

<? php
$ number = 21;
print "Numbers are". $ number;
print "</ br>";
if ($ number% 2 == 0) {
print "Even Numbers";
} Else {
print "odd Numbers";
}
?>

The above code will display "Odd Numbers" on the screen as value of $ number = 21 is an odd number.
1.1.2 Display current number = 21
1.2 "switch" statement
Flow statement following the switch configuration program. One advantage is that you can switch directly assess the status and ordered the action in larger quantities. Switch statement has the following syntax:
switch (expression) {
Case _1 findings:
_1 action;
break;
Case _2 findings:
_2 action;
break;
default:
action if there is an appropriate case;

For details, see the following code:
<? php
Value $ _ Exam = 90;
print "value". $ Value Exam _;
print "<br/>";
switch ($ _ Value Exam) {
if ($ Value Exam _ <50):
print "Sorry, do not pass";
break;
if ($ Value Exam _> = 50):
print "It happens";
break;
default:
break;
}
?>

If executed, the above code will produce such writing image below.
1.2.1 Switches are used to perform switching toset the program flow
Excess switches are alternative actions that could be taken directly without having to write a lot of IF-ELSE multilevel which is more difficult to read. Do not forget to write down a break if You want to get out of the switch when the action has been performed.

1.3 While loop
Differences in human computer is a computer capable told to do the same work over and over again without ever feeling tired. To give orders to the computer to perform repetitive activities, you can use the Loop.

<? php
$ jumlah_ulangan = 0;
while ($ jumlah_ulangan <10) {
$ jumlah_ulangan ++;
print $ jumlah_ulangan. ": Let us learn web programming
with HTML 5 and PHP <br /> ";}
?>

If opened, the while loop above produce reps like The following picture.
1.3.1 While loop to generate repetition

Make While other techniques to create looping, with right conditional statement is placed below. When the code above becomes do while it would be:

<? php
Jumlah_ulangan = 1 $;
do {
print $ jumlah_ulangan. . "Learn web programming
HTML 5 and PHP <br /> ";
$ Jumlah_ulangan ++;
} While ($ jumlah_ulangan <= 10);
?>

It looks like the following
1.3.2 Do while to do reps

SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 komentar:

Posting Komentar