Full page previews coming to Google search

Google has been spotted publicly testing a feature made famous by the SearchPreview for GoogleChrome extension: full-sized result previews. Instead of reading a small excerpt under the link of a result, this feature allows the user to hover over the link and have a popup with a preview of the site. Note that relevant text has been highlighted and enlarged, making it easier to determine if the site contains the information the user is searching for.
This will drastically increase the efficiency of searching with Google. Instead of having to open the link and search for the text on the page, Google shows it to you in a convenient manner. However, there is concern for advertisers and site owners: now searchers don’t visit the site, and ads are not previewed. On top of that, the ads on the side of the results page are blocked by the preview panel.
While this feature is definitely worth implementing, it’s not quite perfect yet. This feature would cause many complaints from advertisers due to lost ad space. If Google can find a way to both preview the ads and avoid blocking their own, this preview mode will be a welcome addition to the search engine.
Source: TheNextWeb

Full page previews coming to Google search

Google has been spotted publicly testing a feature made famous by the SearchPreview for GoogleChrome extension: full-sized result previews. Instead of reading a small excerpt under the link of a result, this feature allows the user to hover over the link and have a popup with a preview of the site. Note that relevant text has been highlighted and enlarged, making it easier to determine if the site contains the information the user is searching for.
This will drastically increase the efficiency of searching with Google. Instead of having to open the link and search for the text on the page, Google shows it to you in a convenient manner. However, there is concern for advertisers and site owners: now searchers don’t visit the site, and ads are not previewed. On top of that, the ads on the side of the results page are blocked by the preview panel.
While this feature is definitely worth implementing, it’s not quite perfect yet. This feature would cause many complaints from advertisers due to lost ad space. If Google can find a way to both preview the ads and avoid blocking their own, this preview mode will be a welcome addition to the search engine.
Source: TheNextWeb

PSP: PlayStation… Phone?

PlayStation PhoneLooks like Sony is actually going to make a PSP-phone hybrid. While the device shown is merely a prototype, Engadget is pretty certain that the PSP is real, and will be released sometime this or next year.
Engadget is reporting that the phone has a 1GHz Qualcomm MSM8655 processor inside, 512MB of RAM, 1GB of ROM, and a screen that’s somewhere between 3.7 and 4.1 inches big. The phone should be equipped with Android 3.0 when released, and comes with a multitouch section for controls, most likely to be used as analog sticks. The phone also comes with a microSD slot instead of a Memory Stick one.
As time progresses, the phone’s design should become more polished, and the OS should get some custom theming eventually, along with a nice PSP emulator of sorts, and perhaps a custom Sony Marketplace for downloading apps and games.

PSP: PlayStation… Phone?

PlayStation PhoneLooks like Sony is actually going to make a PSP-phone hybrid. While the device shown is merely a prototype, Engadget is pretty certain that the PSP is real, and will be released sometime this or next year.
Engadget is reporting that the phone has a 1GHz Qualcomm MSM8655 processor inside, 512MB of RAM, 1GB of ROM, and a screen that’s somewhere between 3.7 and 4.1 inches big. The phone should be equipped with Android 3.0 when released, and comes with a multitouch section for controls, most likely to be used as analog sticks. The phone also comes with a microSD slot instead of a Memory Stick one.
As time progresses, the phone’s design should become more polished, and the OS should get some custom theming eventually, along with a nice PSP emulator of sorts, and perhaps a custom Sony Marketplace for downloading apps and games.

Apple drops the included Flash and Java on OS X

Apple vs Flash
Apple has had a long history of being assaulted by consumers for not supporting Flash on its mobile devices such as the iPhone, iTouch, and more recently the iPad. They have cited numerous reasons for this, such as a large chunk of Flash relies on mouse actions (ex: rollover) and because its creator, Adobe, wants developers to use flash as a creation tool for apps that run on the various Apple touch devices.
In an open letter on Apple.com back in April, Steve Jobs lists many reasons that Flash will have no future with Apple. That letter apparently spoke for the entirety of Apple, because they announced that Adobe Flash will be deprecated from all Apple operating systems and that it will also not be included in Lion, the upcoming Apple OS.
While one can go on and on about Apple vs Flash, another recent deprecation from Apple operating systems is support for Java. Apple has not had much to say about Java in the recent past, but it did drop a Java bridge named Cocoa back in 2005.
Apple changed their application development guidelines to state they will not accept any applications that are based off of or include Java. This is probablly because the apps downloaded on the app store included with Lion will require the user to install Java themselves. And of course, while Flash and Java will no longer come pre-installed, the end-user is completely free to install these platforms on their own.
Even with Apple deprecating Flash and Java in their OS, you can still acquire and use them. For Flash and Java on your Apple computers, you can still install the software yourself. Also, to use Flash on your iPhone, iPod Touch, and iPhone, all you need is to jailbreak them and install the program Frash.

Apple drops the included Flash and Java on OS X

Apple vs Flash
Apple has had a long history of being assaulted by consumers for not supporting Flash on its mobile devices such as the iPhone, iTouch, and more recently the iPad. They have cited numerous reasons for this, such as a large chunk of Flash relies on mouse actions (ex: rollover) and because its creator, Adobe, wants developers to use flash as a creation tool for apps that run on the various Apple touch devices.
In an open letter on Apple.com back in April, Steve Jobs lists many reasons that Flash will have no future with Apple. That letter apparently spoke for the entirety of Apple, because they announced that Adobe Flash will be deprecated from all Apple operating systems and that it will also not be included in Lion, the upcoming Apple OS.
While one can go on and on about Apple vs Flash, another recent deprecation from Apple operating systems is support for Java. Apple has not had much to say about Java in the recent past, but it did drop a Java bridge named Cocoa back in 2005.
Apple changed their application development guidelines to state they will not accept any applications that are based off of or include Java. This is probablly because the apps downloaded on the app store included with Lion will require the user to install Java themselves. And of course, while Flash and Java will no longer come pre-installed, the end-user is completely free to install these platforms on their own.
Even with Apple deprecating Flash and Java in their OS, you can still acquire and use them. For Flash and Java on your Apple computers, you can still install the software yourself. Also, to use Flash on your iPhone, iPod Touch, and iPhone, all you need is to jailbreak them and install the program Frash.

How to get the current class in Java ?

This a question that is often asked by my students:
How to get the current class in Java  ?

In the code below, instead of A.class, I want to something like "get the current class".
One of my student even invent a new syntax for that purpose this.class.
But guess what, the compiler doesn't like invented syntaxes.
  public class A {
public static void main(String[] args) {
System.out.println("current class " + A.class);
}
}
My standard answer was that there is no obvious way to do that.
In fact, there is a hacky way to get the current class using exception, stack trace element and Class.forName.
The way to combine those elements is left as an exercice to the reader.
This is no more true with JDK 7 which will include the JSR 292 API (java.dyn) .
This API provides, as a side effect, a way  to get the current class.
  import java.dyn.MethodHandles;
  
  public class A {
public static void main(String[] args) {
System.out.println(MethodHandles.lookup().lookupClass());
}
}
MethodHandles.lookup() returns a Lookup object which is a factory of method handles.
The Lookup object embodies the class of the code that calls the method lookup().
This class will be used to check if the code has the right or not to create a method handle.
And You can retreive this class using the method lookupClass().
See you soon for tips and tricks on JDK 7/JSR 292.
cheers,
Rémi

How to get the current class in Java ?

This a question that is often asked by my students:
How to get the current class in Java  ?

In the code below, instead of A.class, I want to something like "get the current class".
One of my student even invent a new syntax for that purpose this.class.
But guess what, the compiler doesn't like invented syntaxes.
  public class A {
public static void main(String[] args) {
System.out.println("current class " + A.class);
}
}
My standard answer was that there is no obvious way to do that.
In fact, there is a hacky way to get the current class using exception, stack trace element and Class.forName.
The way to combine those elements is left as an exercice to the reader.
This is no more true with JDK 7 which will include the JSR 292 API (java.dyn) .
This API provides, as a side effect, a way  to get the current class.
  import java.dyn.MethodHandles;
  
  public class A {
public static void main(String[] args) {
System.out.println(MethodHandles.lookup().lookupClass());
}
}
MethodHandles.lookup() returns a Lookup object which is a factory of method handles.
The Lookup object embodies the class of the code that calls the method lookup().
This class will be used to check if the code has the right or not to create a method handle.
And You can retreive this class using the method lookupClass().
See you soon for tips and tricks on JDK 7/JSR 292.
cheers,
Rémi

What Computer Programming Language To Learn Next?

After all these rumors on Microsoft buying Adobe, several people asked me what do I think of it,  and, of course the second question was (it’s always on the mind of every professional software developer), “What to learn next?”

To be honest with you, this news didn’t get me excited that much. If this will happen, it’ll be definitely more beneficial for Adobe products. With all my respect to Adobe engineers, I believe that Microsoft has a lot more experience in developing and RELEASING software than Adobe.  If this happen, Flash and Silverlight will control most of the video delivery market on the Web, and the weak motivation of turning HTML 5 into a standard will simply vanish.
Will Flash and Silverlight merge into a FlashLight? I doubt it. Both of these runtimes can live as good neighbors on every device including iPhones. I still believe that Apple will stop playing stupid and will let Flash Player on iOS – the sooner the better for them. Steve Jobs should do it at least for the sake of getting a standing ovation during his next year keynote when he’ll state that over the last year Flash Player has resolved its technical challenges and we decided to let it in. Whatever. Just do it.

Will I start studying Silverlight and the whole shebang that comes with it?  No. I’m a Java developer who spent the last four years of my life developing applications having Adobe Flex clients talking with Java-based servers.  And regardless of what some people say after recent actions of driven-by-lawyers Oracle’s, Java is stronger than ever.

I highly recommend you to give a close look to Java EE 6 – which is a robust and easy (I mean it) to use enterprise platform.  If Adobe will decide to move away from Java and cater to .Net then be it. But I’m staying with Java!



source:http://java.sys-con.com/node/1566256

What Computer Programming Language To Learn Next?

After all these rumors on Microsoft buying Adobe, several people asked me what do I think of it,  and, of course the second question was (it’s always on the mind of every professional software developer), “What to learn next?”

To be honest with you, this news didn’t get me excited that much. If this will happen, it’ll be definitely more beneficial for Adobe products. With all my respect to Adobe engineers, I believe that Microsoft has a lot more experience in developing and RELEASING software than Adobe.  If this happen, Flash and Silverlight will control most of the video delivery market on the Web, and the weak motivation of turning HTML 5 into a standard will simply vanish.
Will Flash and Silverlight merge into a FlashLight? I doubt it. Both of these runtimes can live as good neighbors on every device including iPhones. I still believe that Apple will stop playing stupid and will let Flash Player on iOS – the sooner the better for them. Steve Jobs should do it at least for the sake of getting a standing ovation during his next year keynote when he’ll state that over the last year Flash Player has resolved its technical challenges and we decided to let it in. Whatever. Just do it.

Will I start studying Silverlight and the whole shebang that comes with it?  No. I’m a Java developer who spent the last four years of my life developing applications having Adobe Flex clients talking with Java-based servers.  And regardless of what some people say after recent actions of driven-by-lawyers Oracle’s, Java is stronger than ever.

I highly recommend you to give a close look to Java EE 6 – which is a robust and easy (I mean it) to use enterprise platform.  If Adobe will decide to move away from Java and cater to .Net then be it. But I’m staying with Java!



source:http://java.sys-con.com/node/1566256

ChangeBASE launches IE8 web browser compatibility and rendering tool, AOK Browse-It

London, 12th October 2010 - ChangeBASE Limited, the global leader in automated application compatibility testing and remediation, today announces the launch of AOK Browse-It, a tool to enhance website rendering functionality for Internet Explorer 8 (IE8). The AOK Browse-It module adds to ChangeBASE's existing portfolio of compatibility testing and remediation products, enabling organisations to speed up their migrations to IE8 and enjoy the benefits the new browser brings, by overcoming this last compatibility hurdle.
With the launch of Windows 7 and IE8 as the embedded browser, compatibility for web-based applications and websites is crucial to ensure a smooth and cost-efficient migration, as well as long-term staff productivity. The compatibility challenges facing organisations migrating to IE8 fall into two categories. Firstly and critically, rendering or presentation issues; where a web-based page may not render or display correctly or certain buttons or links may not work. The second being compatibility of web-based applications that need to integrate with the browser to enable functionality - for example where services have been deprecated or restricted within IE that are required by the application, such as DEP/NX. AOK Browse-It addresses both of these issues.
AOK Browse-It covers all the pertinent issues of web application compatibility and is the first and only solution on the market able to address the entire spectrum of IE8 compatibility challenges. The module addresses web-based application compatibility testing in the same way as it does for native application testing. Bulk loading of web-based applications is enabled and these are then rapidly assessed for compatibility, with an in-depth report being produced.
Uniquely, it is AOK Browse-It's compatibility testing and reporting for websites, intranets, extranets and portals that differentiates it from any other solution on the market. The tool's capability is based upon collecting extensive data from three sources - URLs, source code files and client-based user browsing reporting on actual desktop usage. AOK Browse-It then carries out in-depth testing for compatibility for IE8, providing granular reporting back to the administrator including precise detail on any compatibility issues found and how to fix them. This compatibility report enables organisations to develop budget, resource and time plans for each cost centre, meaning the entire migration process can be carried out as efficiently and cost-effectively as possible.
The five biggest challenges of IE8 migration
From extensive testing via the Beta programme, ChangeBASE has identified five key challenges facing organisations as they plan and execute migrations to Internet Explorer 8. ChangeBASE's AOK Browse-It tool is the only solution that can address each of these challenges, enabling organisations to speed-up and reduce the cost of their migration projects:
  1. Inaccurate browser detection scriptsThe most common issue is poorly constructed browser detection scripts. Historically, engineers and developers write scripts to indicate which browser they are using - in the majority of cases, these were written long before IE7 or IE8 were available. For older websites written in JAVA or other languages, they have often not been coded to the industry standards required today. This is an age issue and organisations will increasingly find non-compatibility issues with IE8 and beyond. Ultimately, scripts do not test for IE8 and therefore will not highlight an issue, whereas AOK Browse-It will identify where these script issues occur through its testing capabilities.
  2. Poorly constructed conditional commentsConditional comments are a way of hiding script and are linked to version checking processes. Poorly constructed conditional comments will not recognise IE8 and as a result, IE8 checking errors will not be indicated. AOK Browse-It will identify these issues enabling organisations to take the appropriate action.
  3. Combining secure and non-secure items
    A mixture of secure and non-secure items on a single web page can generate significant issues - arising from the fact that all links on a secure web page need to be entitled as https. These challenges highlight quality and consistency issues, as a result of human involvement in the initial site build. AOK Browse-It's checking functionality identifies these inconsistencies.
  4. Case sensitivity in XML code
    XML is primarily used as the navigation code for web pages and here, case sensitivity is key - things that worked under IE6 may not work under IE8. This issue is again down to human error and consistency at the build stage. These errors are easy to fix but can be extremely difficult to identify. AOK Browse-It will provide the necessary XML identification and compatibility status in its granular reports.
  5. ActiveX security restrictions
    Finally, ActiveX security restrictions may affect some web-based applications. ActiveX applets are downloaded onto the user's desktop to help view web pages correctly and provide enhanced functionality. These ActiveX applets can result in serious open security vulnerabilities which AOK Browse-It will detect and enable precise action to be taken.

ChangeBASE launches IE8 web browser compatibility and rendering tool, AOK Browse-It

London, 12th October 2010 - ChangeBASE Limited, the global leader in automated application compatibility testing and remediation, today announces the launch of AOK Browse-It, a tool to enhance website rendering functionality for Internet Explorer 8 (IE8). The AOK Browse-It module adds to ChangeBASE's existing portfolio of compatibility testing and remediation products, enabling organisations to speed up their migrations to IE8 and enjoy the benefits the new browser brings, by overcoming this last compatibility hurdle.
With the launch of Windows 7 and IE8 as the embedded browser, compatibility for web-based applications and websites is crucial to ensure a smooth and cost-efficient migration, as well as long-term staff productivity. The compatibility challenges facing organisations migrating to IE8 fall into two categories. Firstly and critically, rendering or presentation issues; where a web-based page may not render or display correctly or certain buttons or links may not work. The second being compatibility of web-based applications that need to integrate with the browser to enable functionality - for example where services have been deprecated or restricted within IE that are required by the application, such as DEP/NX. AOK Browse-It addresses both of these issues.
AOK Browse-It covers all the pertinent issues of web application compatibility and is the first and only solution on the market able to address the entire spectrum of IE8 compatibility challenges. The module addresses web-based application compatibility testing in the same way as it does for native application testing. Bulk loading of web-based applications is enabled and these are then rapidly assessed for compatibility, with an in-depth report being produced.
Uniquely, it is AOK Browse-It's compatibility testing and reporting for websites, intranets, extranets and portals that differentiates it from any other solution on the market. The tool's capability is based upon collecting extensive data from three sources - URLs, source code files and client-based user browsing reporting on actual desktop usage. AOK Browse-It then carries out in-depth testing for compatibility for IE8, providing granular reporting back to the administrator including precise detail on any compatibility issues found and how to fix them. This compatibility report enables organisations to develop budget, resource and time plans for each cost centre, meaning the entire migration process can be carried out as efficiently and cost-effectively as possible.
The five biggest challenges of IE8 migration
From extensive testing via the Beta programme, ChangeBASE has identified five key challenges facing organisations as they plan and execute migrations to Internet Explorer 8. ChangeBASE's AOK Browse-It tool is the only solution that can address each of these challenges, enabling organisations to speed-up and reduce the cost of their migration projects:
  1. Inaccurate browser detection scriptsThe most common issue is poorly constructed browser detection scripts. Historically, engineers and developers write scripts to indicate which browser they are using - in the majority of cases, these were written long before IE7 or IE8 were available. For older websites written in JAVA or other languages, they have often not been coded to the industry standards required today. This is an age issue and organisations will increasingly find non-compatibility issues with IE8 and beyond. Ultimately, scripts do not test for IE8 and therefore will not highlight an issue, whereas AOK Browse-It will identify where these script issues occur through its testing capabilities.
  2. Poorly constructed conditional commentsConditional comments are a way of hiding script and are linked to version checking processes. Poorly constructed conditional comments will not recognise IE8 and as a result, IE8 checking errors will not be indicated. AOK Browse-It will identify these issues enabling organisations to take the appropriate action.
  3. Combining secure and non-secure items
    A mixture of secure and non-secure items on a single web page can generate significant issues - arising from the fact that all links on a secure web page need to be entitled as https. These challenges highlight quality and consistency issues, as a result of human involvement in the initial site build. AOK Browse-It's checking functionality identifies these inconsistencies.
  4. Case sensitivity in XML code
    XML is primarily used as the navigation code for web pages and here, case sensitivity is key - things that worked under IE6 may not work under IE8. This issue is again down to human error and consistency at the build stage. These errors are easy to fix but can be extremely difficult to identify. AOK Browse-It will provide the necessary XML identification and compatibility status in its granular reports.
  5. ActiveX security restrictions
    Finally, ActiveX security restrictions may affect some web-based applications. ActiveX applets are downloaded onto the user's desktop to help view web pages correctly and provide enhanced functionality. These ActiveX applets can result in serious open security vulnerabilities which AOK Browse-It will detect and enable precise action to be taken.

C break and continue Statements

break statement is used to break any type of loop such as whiledo while an for loop.break statement terminates the loop body immediately. continue statement is used to break current iteration. After continue statement the control returns to the top of the loop test conditions.
Here is an example of using break and continue statement:

#include <stdio.h>
#define SIZE 10
void main(){

// demonstration of using break statement

int items[SIZE] = {1,3,2,4,5,6,9,7,10,0};

int number_found = 4,i;

for(i = 0; i < SIZE;i++){

if(items[i] == number_found){

printf("number found at position %d\n",i);

break;// break the loop

}
printf("finding at position %d\n",i);
}

// demonstration of using continue statement
for(i = 0; i < SIZE;i++){

if(items[i] != number_found){

printf("finding at position %d\n",i);

continue;// break current iteration
}

// print number found and break the loop

printf("number found at position %d\n",i);

break;
}

}

Here is the output
finding at position 0
finding at position 1
finding at position 2
number found at position 3
finding at position 0
finding at position 1
finding at position 2
number found at position 3

source:http://cprogramminglanguage.net/c-break-continue-statements.aspx

C break and continue Statements

break statement is used to break any type of loop such as whiledo while an for loop.break statement terminates the loop body immediately. continue statement is used to break current iteration. After continue statement the control returns to the top of the loop test conditions.
Here is an example of using break and continue statement:

#include <stdio.h>
#define SIZE 10
void main(){

// demonstration of using break statement

int items[SIZE] = {1,3,2,4,5,6,9,7,10,0};

int number_found = 4,i;

for(i = 0; i < SIZE;i++){

if(items[i] == number_found){

printf("number found at position %d\n",i);

break;// break the loop

}
printf("finding at position %d\n",i);
}

// demonstration of using continue statement
for(i = 0; i < SIZE;i++){

if(items[i] != number_found){

printf("finding at position %d\n",i);

continue;// break current iteration
}

// print number found and break the loop

printf("number found at position %d\n",i);

break;
}

}

Here is the output
finding at position 0
finding at position 1
finding at position 2
number found at position 3
finding at position 0
finding at position 1
finding at position 2
number found at position 3

source:http://cprogramminglanguage.net/c-break-continue-statements.aspx

for Loop Statement

There are three parts which is separated by semi-colons in control block of the for loop.
initialization_expression is executed before execution of the loop starts. This is typically used to initialize a counter for the number of loop iterations. You can initialize a counter for the loop in this part.
The execution of the loop continues until the loop_condition is false. This expression is checked at the beginning of each loop iteration.
The increment_expression, is usually used to increment the loop counter. This is executed at the end of each loop iteration.
Here is an example of using for loop statement to print an integer five times

#include <stdio.h>

void main(){
// using for loop statement
int max = 5;
int i = 0;
for(i = 0; i < max;i++){

printf("%d\n",i);

}
}

for Loop Statement

There are three parts which is separated by semi-colons in control block of the for loop.
initialization_expression is executed before execution of the loop starts. This is typically used to initialize a counter for the number of loop iterations. You can initialize a counter for the loop in this part.
The execution of the loop continues until the loop_condition is false. This expression is checked at the beginning of each loop iteration.
The increment_expression, is usually used to increment the loop counter. This is executed at the end of each loop iteration.
Here is an example of using for loop statement to print an integer five times

#include <stdio.h>

void main(){
// using for loop statement
int max = 5;
int i = 0;
for(i = 0; i < max;i++){

printf("%d\n",i);

}
}

do-while Loop Statement

do while loop statement allows you to execute code block in loop body at least one. Here is do while loop syntax:

do {
// statements
} while (expression);

Here is an example of using do while loop statement:

#include <stdio.h>
void main(){
int x = 5;
int i = 0;
// using do while loop statement
do{
i++;
printf("%d\n",i);
}while(i < x);

}

The program above print exactly 5 times as indicated in do while loop body

do-while Loop Statement

do while loop statement allows you to execute code block in loop body at least one. Here is do while loop syntax:

do {
// statements
} while (expression);

Here is an example of using do while loop statement:

#include <stdio.h>
void main(){
int x = 5;
int i = 0;
// using do while loop statement
do{
i++;
printf("%d\n",i);
}while(i < x);

}

The program above print exactly 5 times as indicated in do while loop body

While Loop Statement

A loop statement allows you to execute a statement or block of statements repeatedly. The while loop is used when you want to execute a block of statements repeatedly with checked condition before making an iteration. Here is syntax of while loop statement:

while (expression) {
// statements
}

This loop executes as long as the given logical expression between parentheses afterwhile is true. When expression is false, execution continues with the statement following the loop block. The expression is checked at the beginning of the loop, so if it is initially false, the loop statement block will not be executed at all. And it is necessary to update loop conditions in loop body to avoid loop forever. If you want to escape loop body when a certain condition meet, you can use break statement
Here is a while loop statement demonstration program:

#include <stdio.h>

void main(){
int x = 10;
int i = 0;

// using while loop statement
while(i < x){
i++;
printf("%d\n",i);
}


// when number 5 found, escape loop body
int numberFound= 5;
int j = 1;
while(j < x){
if(j == numberFound){
printf("number found\n");
break;
}
printf("%d...keep finding\n",j);
j++;
}

}

And here is the output:
1
2
3
4
5
6
7
8
9
10
1...keep finding
2...keep finding
3...keep finding
4...keep finding
number found

source:http://cprogramminglanguage.net/c-while-loop-statement.aspx

While Loop Statement

A loop statement allows you to execute a statement or block of statements repeatedly. The while loop is used when you want to execute a block of statements repeatedly with checked condition before making an iteration. Here is syntax of while loop statement:

while (expression) {
// statements
}

This loop executes as long as the given logical expression between parentheses afterwhile is true. When expression is false, execution continues with the statement following the loop block. The expression is checked at the beginning of the loop, so if it is initially false, the loop statement block will not be executed at all. And it is necessary to update loop conditions in loop body to avoid loop forever. If you want to escape loop body when a certain condition meet, you can use break statement
Here is a while loop statement demonstration program:

#include <stdio.h>

void main(){
int x = 10;
int i = 0;

// using while loop statement
while(i < x){
i++;
printf("%d\n",i);
}


// when number 5 found, escape loop body
int numberFound= 5;
int j = 1;
while(j < x){
if(j == numberFound){
printf("number found\n");
break;
}
printf("%d...keep finding\n",j);
j++;
}

}

And here is the output:
1
2
3
4
5
6
7
8
9
10
1...keep finding
2...keep finding
3...keep finding
4...keep finding
number found

source:http://cprogramminglanguage.net/c-while-loop-statement.aspx

Follow by Email

There was an error in this gadget