Greenfoot sound file types3/15/2024 The crab will turn 67 radians anti-clockwise.The crab will turn 67 radians clockwise.The crab will turn 67 degrees anti-clockwise.The crab will turn 67 degrees clockwise.The Crab will still get stuck at the end of the world. Let’s see what happens when we use this code… WAIT!!!īefore we test this out, can you guess what will happen? Solution? Turn around if the at the world’s edge. The first problem with our crab was that it moves only one direction and if it hits the world’s edge, it gets stuck there. You can think of this as if they were parts of sentences that aren’t finished yet. However, do notice that lines like if () or most loops – which you will learn later – do not require you to (aka don’t do) put ‘ ’ at the end of the line. If you don’t put one in, the program will get confused and reply to you with error messages. This is like a full stop at the end of a sentence. Note that I put a semi-colon at the end of each method. Let’s see how this new logic worksĭoesn’t this sound fairly natural to you? I mean, if you’re hungry you eat food, right? Let’s see another exampleĭid you notice that I used parentheses () next to if – where I put in the parameter, and curly brackets below with the to do list inside? This type can be simplified like this It takes a boolean parameter (remember true/false) and gives the program the ability either to commence something or to skip it. The if statement is one of the most widely used one in any programming language. One of the most frequently used condition is the if statement In order to make objects do certain actions in certain circumstance, a conditional statement is required. Because this is all it can do, when it hits the end of the world, it does not know what to do thus, stops moving. Right now, as you can see, all the crab is able to do is move. Okay, remember how to open the editor? Let’s double click on the Crab class icon on the right. So in this lesson, we’re going to make it go all over the place and eat something. Last lesson we were able to get out crab move from left to rightīut this isn’t all that interesting to watch for long, is it? But that aside, did u notice how I used the comments? Yeah, that’s how you should use them. joking, it doesn’t have to be really important… but where the fun in that?ĭid u get it? It’s kinda confusing, right? It was confusing for me the first time □īut we’ll see how this works later on with more examples. * This method will work as an example of how to write a method. Where should we start? Well, it all starts with a … If you put all codes in one single run method, first of all, it’ll be really hard to see and not to mention, slow down the program – since the program will have to read through all the long program to find the code it actually will use.įor this, you will start creating methods. There is nothing wrong with this, except as you advance in the art of programming, you will find your program becoming longer and longer. Until now, I just put all the methods in the run method. * all lines until they see a “*/” or an asterisk and a slash, which signifies the end of a MLC. * They start with “/*” or a slash and an asterisk and they continue on * descriptions of the actor, or key methods in the program. * Mutiple Line Comments (MLC) are generally colored blue. On the other hand, there is a multiple line comments. They are mostly used for commenting on methods and giving short descriptions of small details in the program. The Single Line Comment (SLC) always comes after “//” or two slashes. One is the single line comment, the other is the … you guessed it – the multiple line comment. In Greenfoot – as well as some other programs – there are 2 major ways of writing comments. Hi all! Today I wanted to give y’all some info.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |