Goddess Day confession: Rejected for a semicolon

The semicolon does not carry the burden

March 8 is Women’s Day in China, and March 7 is commonly known as Goddess Day, and every year the banner of goddess Day is decorated with flowers on campus.

Just a few years ago, a boy of grade 14, a soft 4, made a banner for his fellow girls, which also read:

for(int i=0; i<forever; i++);printf("I Love My Girl");
Copy the code

So what does this code mean?

I love my girl forever.

The banner was really creative, but there was a serious problem with the code:

I laughed when I added a semicolon to the for statement, which would loop through the null operation several times before executing the second printf statement, which would be forever.

So the girl refused the boy.

A sad story.

Take a look at the comments:

In addition, when I copy this code, it doesn’t work at all. Because this C code is a shorthand, it’s missing a lot of things. We also need not seriously ha ~

Let me show you the error:

I made some minor changes, defining the variables forever and I, and changing the semicolon after for to curly braces. Since forever is an infinitely positive number, I’ll simplify it to 100 instead.

#include <stdio.h>

void main (a) {
	int forever = 100;
	int i;
	for( i=0; i<forever; i++) {
		printf("I Love My Girl"); }}Copy the code

This time the execution result is correct:Another student saw the tragedy of the past and improved the code to solve the semicolon problem. Take a look:It’s always girls’ Day. It warms my heart!

What other languages need semicolons

C language needs semicolons to break sentences. Which other languages need semicolons?

I put my common language listed here, we can leave a message to supplement or correct, after writing code must pay attention to.

2. Requiring a semicolon:

  • PHP, Java, C++, C#, SQL, Pascal

2. Not requiring a semicolon:

  • Python

Semicolons are optional:

  • JavaScript
  • Scala

Other creative banners

  • 0 error is not worth your smile

This must beA compiler errorToo many.

  • Binary 520

This is easy, I can see it, binary to decimal, 520, haha!

  • Variable assignment

    Girls_Day::isHappy = true;
    Copy the code

Seriously, the name here is both underline and hump, this student, pay attention to the code specification!

  • Object and scope

The students in this class are very impressive, with object oriented play out a flower,The goddess of our class is protected by the boys of our class!

  • Zero and one, the computer understands both

All right, Goddess Day, take the banner, and give it to whatever you likeThe girlSend wechat! This time,Off the single stability!

(Source of banner image)


About the author: Wu Kong, 8 years of experience in Internet development and architecture, explains distributed and architecture design with stories. “JVM performance optimization practice” column author, open source “Spring Cloud practice PassJava” project, independently developed a PMP brush small program. Pay attention to the public account: Wukong chat framework can be free to brush questions.

I am Wukong, strive to become stronger, become super Saiya people!