Hey guys, Master Jake here. I just got down filming my first video blog and I decided to go ahead and get directly into another tutorial. The tutorial content for this one is going to be about comparison operators in batch.
So, let’s go ahead and jump right in. If you don’t know what comparison operators are, they are equal to, greater than, less than, not equal to, greater or less than or equal to and greater than or equal to. Now, the ones I’m using right there on the left side, this is a text its what’s defining it and they usually work in quite a bit of languages but this over here is not the one used for batch. This is like a Java script uses these comparison operators, C++ uses these comparison operators, Visual Basic has a different comparison operator for not equal to which is like that. But we’re going to be learning the batch ones today and what comparison operators do is they are extremely good because you need them to even test out anything basically. They go along with “if” statements pretty much, they can be used for other stuff but mostly “if” statements is what they’re used in at least in batch, because “if” statements are one of the main test stuff.
So normally, what you’ve learned so far if you’ve watched my “if” statements tutorial, if one equals or if var1 equals to something, do something, something like that but these are a little bit different. So basically, what we’re going to do is I’m going to list them for you first. And you go ahead and write these down if you want.
There they are, just—if you haven’t seen this, this is just a little way of commenting stuff. Alright so, we’re just going to leave that up there and we can actually still write our batch file because they’re all that’s commented out so go ahead and put echo off at the very, very top. Alright, so those are the comparison operators are used in here. And basically, what I’m going to be doing today is creating a program that will simply wait for the user to input a number and then tell the user if that number is greater than another number; less than or equal to.
We’ll actually have on input both. If you heard that sound I just got a complete download. Okay, so the first thing that’s going to do, we’ll go ahead and write a clear screen command just in case something’s on there when they run it. And then we want it to set a variable, we’ll call it “Maxnum” equals enter the maximum number. And then set the “Nextnum” into the testing number.
Alright, now here’s where we’re going to do the test at. If—remember to put percent around variables whether you’re declaring their exact values through their name. If “nextnum” percent, then we want a value here, we’ll put a EQU for equal to; is equal to “maxnum” then we want it to echo—“nextnum” is equal to “maxnum”. Alright and as for that one, and if the “nextnum” is not or we won’t do that one or less than “maxnum” eacho “nextnum” is less than “maxnum”. This is actually going to echo the value for them. So if “maxnum” is four and next number is a two, then it will be two is less than four. If “nextnum” is greater than “maxnum” echo, “nextnum” is greater than and I’ll just do those three because those are the simpler ones, and the other ones are—they work the same way that three is enough for the test to show you the basic idea.
And then we want a greater nul pause and I’ll just have it exit. So let's save this, we’ll just call it testcomp dot bat. Make sure dot bat is on the end, change the save type to all files. If you watch my other tutorials you’ll be fine following along with this. Alright, maximum number, we’re going to make it 10. The testing number is going to be seven this time; seven is less than ten, that is true, that is true. So, you see that it worked there, we’re going to open a back up. 25 is equal to 25, that is also true. And then we’ll do another one, a hundred and that, and that is true.
So, you can see how they work. So that is how the comparison operators function and you can use them in your—I guess I should say programs now to initialize and execute stuff, and that’s just for your own personal enjoyment there. So that is the end of this small tutorial, remember if you like my tutorial, subscribe to me and my site will be coming back up soon. So, just visit it masterjake.co.nr and I’ll see you guys later.
Transcription by:
Scribe4you Transcription Services