Jump to content
Sign in to follow this  
Maffe811

C++ question!

Recommended Posts

Maffe811

Now, the reason i started with AutoIt was that it would hopefully lead me into the coding world and learn the basics before i took on C.

Now my friend that helped me get going, thinks im rappidly progressing with AutoIt and he suggested i should look at C++.

So im looking at some example scripts when i get to the script below.

And my question is, do AutoIt have an equvilant(?) to n-- ?

Because i have always used n=n-1.

// countdown using a for loop
#include <iostream>
using namespace std;
int main ()
{
  for (int n=10; n>0; n--) {
    cout << n << ", ";
  }
  cout << "FIRE!\n";
  return 0;
}

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
jvanegmond

The question is, why not:

for (int n=10; n>0; n-=1) {
Edited by Manadar

Share this post


Link to post
Share on other sites
Mobius

In the c source the n-- component of the for loop as you would expect is to decrement integer n by 1, within a for loop in AutoIt3 the facility of the increment / decrement instruction is handled by the optional STEP parameter, default c equivelent without the step parameter would be n++

AutoIt3 example

_Main()
;
FUNC _Main()
FOR $n = 10 TO 1 STEP -1
    ConsoleWrite($n &',')
NEXT
ConsoleWrite('FIRE!'& @LF)
RETURN 0
ENDFUNC
Edited by Mobius

Share this post


Link to post
Share on other sites
Maffe811

The question is, why not:

for (int n=10; n>0; n-=1) {

Its not my script.

Its an example script.

Closest thing in AutoIt3 is:

$n -= 1

Okay, thats what i needed to know :huh2:

I expect $n += 1 goes upwards ?

In the c source the n-- component of the for loop as you would expect is to decrement integer n by 1, within a for loop in AutoIt3 the facility of the increment / decrement instruction is handled by the optional STEP parameter, default c equivelent without the step parameter would be n++

AutoIt3 example

_Main()
;
FUNC _Main()
FOR $n = 10 TO 1 STEP -1
    ConsoleWrite($n &',')
NEXT
ConsoleWrite('FIRE!'& @LF)
RETURN 0
ENDFUNC

Okay, so now i have both the $n -= 1 and The Step parameter to use.

Thanks for clearing it up for me ;)


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
Mat

The question is, why not:

for (int n=10; n>0; n-=1) {

and why not:

for (int n=10; n>0; n+=-1) {

They all compile the same in the end.

Share this post


Link to post
Share on other sites
Valik

C++ source code is not called "script".

Share this post


Link to post
Share on other sites
Maffe811

Should i just call it C++ code then ?


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
ProgAndy

Should i just call it C++ code then ?

That's right.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Maffe811

Ask for one thing, then you learn two things.

I love this forum.


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×