ForLoop.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. var x = 6;
  6. var giraffe = 8;
  7. var zebra = x + giraffe;
  8. function f(t) {
  9. return t + t;
  10. }
  11. var cat = f(zebra);
  12. rat = cat * 2;
  13. while (rat > 4) {
  14. rat = rat - 3;
  15. cat = cat + 4;
  16. }
  17. for (var i = 4; i < zebra; ++i) {
  18. cat = cat - 1;
  19. }
  20. var dragon = rat / 2;
  21. dragon += 8;
  22. WScript.Echo(x)
  23. WScript.Echo(giraffe)
  24. WScript.Echo(zebra)
  25. WScript.Echo(cat)
  26. WScript.Echo(rat)
  27. WScript.Echo(dragon);
  28. function MatchCollectionLocalCollection(collection, value)
  29. {
  30. for (var i = 0; i < collection.length; i++)
  31. {
  32. if (collection[i] == value)
  33. return true;
  34. }
  35. return false;
  36. }
  37. WScript.Echo(MatchCollectionLocalCollection(["car", "truck"] , "car"));
  38. WScript.Echo(MatchCollectionLocalCollection(["car", "truck"] , "foo"));
  39. var gCollection = ["car", "truck"];
  40. function MatchCollectionGlobalCollection(value)
  41. {
  42. for (var i = 0; i < gCollection.length; i++)
  43. {
  44. if (gCollection[i] == value)
  45. return true;
  46. }
  47. return false;
  48. }
  49. WScript.Echo(MatchCollectionGlobalCollection("car"));
  50. WScript.Echo(MatchCollectionGlobalCollection("foo"));
  51. function MatchCollectionGlobalCollectionandValue()
  52. {
  53. for (var i = 0; i < gCollection.length; i++)
  54. {
  55. if (gCollection[i] == gValue)
  56. return true;
  57. }
  58. return false;
  59. }
  60. var gValue = "car";
  61. WScript.Echo(MatchCollectionGlobalCollectionandValue());
  62. gValue = "foo";
  63. WScript.Echo(MatchCollectionGlobalCollectionandValue());